import {fetchList, delObj,assessIndustrialImport,} from '../api/assessindustrial.js'
import client from './client-export'
import assessIndustrialAdd from "./add.vue"
import assessIndustrialEdit from "./edit.vue"
import {validateUser, validateUserCreateBy} from "../api/assessindustrial";

export default {
    name: 'assess-industrial',
    components: {assessIndustrialAdd,assessIndustrialEdit,client},
    provide() {
        return {
            initList: this.getListData,
        };
    },
    data() {
        return {
            user:[],
            params: {
                current: 1,
                size: 10,
                parkName: ''
            },
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 10 // 每页显示多少条
            },
            spanArr: {
                valueOne: [],
                valueTwo:[],
            },
            pos:'',
            tableData: [],//列表主数据
            multipleSelection: [],//表格选中行对象数组
            /*过滤List*/
            filterList:[
                {
                    label: '年份',
                    inputType:'dict',
                    dictName:'year',
                    name:'year',
                    multiple:true,
                },
                {
                    label: '考核结果',
                    inputType:'dict',
                    dictName:'assess_industrial_result',
                    name:'assess',
                    multiple:true,
                },
                {
                    label:'进驻园区',
                    type:'input',
                    name:'parkName',
                },
                {
                    label:'合同开始日期',
                    inputType: 'daterange',
                    name:['contractStartTmStart','contractStartTmEnd']
                },
                {
                    label:'合同结束日期',
                    inputType: 'daterange',
                    name:['contractEndTmStart','contractEndTmEnd']
                },
                {
                    label:'纳税总额',
                    inputType:'numberRange',
                    name:['totalTaxStart','totalTaxEnd'],
                },
                {
                    label:'年产值',
                    inputType:'numberRange',
                    name:['yearOutputStart','yearOutputEnd'],
                },
            ],
        }
    },
    beforeMount(){
        this.getListData();
    },
    methods: {
        /*绑定重置按钮*/
        searchReset() {
            this.getListData()
        },
        // 菜单点击监听
        handleMenuClick(type){
            switch (type) {
                case 'add':
                    this.$router.push("/wy-exam/exam-industrial/editExam").then(r => {});
                    break;
                case 'export':
                    this.$refs.client.show();
                    break;
            }
        },
        /*获取页面tableData*/
        getListData(params={}) {
            let req  =  {...this.params,...params}
            fetchList(req).then(res=>{
                let {size,current,total,records} = res.data.data
                this.tableData=records
                this.getSpanArr(records)
                this.params=req
                this.pager = {size,current,total}
            })
        },
        /*删除*/
        del(row) {
            /*获取当前登录用户*/
            validateUser().then((res)=>{
                this.user=res.data.data
            })
            /*判断是否相同部门*/
            validateUserCreateBy(row.createBy).then(res=>{
                if(res.data.data==this.user.user.deptId){
                    this.confirm('删除确认', '您确定要删除该数据吗？', () => {
                        delObj(row.assessIndustrialId).then(resp => {
                            if (resp.data.code == 0) {
                                this.suc('删除成功')
                                this.getListData()
                            } else {
                                this.err('删除失败' + resp.data.code + resp.data.message)
                            }
                        })
                    })
                }else{
                    this.$message.error("您没有权限修改信息")
                }
            })
        },
        /*合并行数*/
        getSpanArr(data){
            this.spanArr.valueOne=[]
            this.spanArr.valueTwo=[]
            for(var i=0;i<data.length;i++){
                if(i==0){
                    this.spanArr.valueOne.push(1)
                    this.spanArr.valueTwo.push(1)
                    this.pos=0
                }else{
                    if(data[i].parkName==data[i-1].parkName  &&  data[i].year==data[i-1].year){
                        this.spanArr.valueOne[this.pos]+=1
                        this.spanArr.valueOne.push(0)
                        if(data[i].companyName == data[i-1].companyName){
                            this.spanArr.valueTwo[this.pos]+=1
                            this.spanArr.valueTwo.push(0)
                        }else{
                            this.spanArr.valueTwo.push(1)
                        }
                    }else{
                        this.spanArr.valueOne.push(1)
                        this.spanArr.valueTwo.push(1)
                        this.pos=i
                    }
                }
            }
        },
        /*el-table直接调用*/
        objectSpanMethod({row,column,rowIndex,columnIndex}){
            if(columnIndex==0  || columnIndex==1 ||  columnIndex==2 ){
                const  _row = this.spanArr.valueOne[rowIndex]
                const _col = _row>0?1:0
                return {
                    rowspan:_row,
                    colspan:_col
                }
            }else if(columnIndex == 3) {
                const  _row = this.spanArr.valueTwo[rowIndex]
                const _col = _row>0?1:0
                return {
                    rowspan:_row,
                    colspan:_col
                }
            }else{
                /*如果是第一行*/
                for(var i=0;i<this.spanArr.valueOne.length;i++){
                    if(this.spanArr.valueOne[i]>1){
                        if(rowIndex==(i+this.spanArr.valueOne[i]-1)){
                            return{
                                rowspan: 1,
                                colspan: 1
                            }
                        }
                    }
                }
            }
        },
    },


}
